#include "player.h"

void Player::move(int direction){
	//direction = 1 : up
	//			  2 : down
	//			  3 : left
	//			  4 : right
	switch(direction){
		case 1:
		Sprite::velocityY(-200);break;
		case 2:
		Sprite::velocityY(200);break;
		case 3:
		Sprite::velocityX(-200);break;
		case 4:
		Sprite::velocityX(200);break;
	}
}

void Player::stop(){
	Sprite::velocityX(0);
	Sprite::velocityY(0);
}

void Player::update(unsigned ticks){
  MultiSprite::update(ticks);
  float incr = velocityY() * static_cast<float>(ticks) * 0.001;
  Y( Y()+incr );
  float height = static_cast<float>(frame->getHeight());
  if ( Y() < 0) {
    Y(0);
  }
  if ( Y() > gameData->getXmlInt("worldHeight")-height) {
     Y(gameData->getXmlInt("worldHeight")-height);
  }
  incr = velocityX() * static_cast<float>(ticks) * 0.001;
  X( X()+incr );
  float width = static_cast<float>(frame->getWidth());
  if ( X() < 0) {
    X(0);
  }
  if ( X() >  gameData->getXmlInt("worldWidth")-width) {
    X(gameData->getXmlInt("worldWidth")-width);
  }
}

void Player::draw() const {
  MultiSprite::draw();
}


